<?php
// 直接连接数据库
$host = '127.0.0.1';
$dbname = 'dyorder';
$username = 'root';
$password = '';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    // 检查orders表是否存在
    $stmt = $pdo->query('SHOW TABLES LIKE "orders"');
    $tables = $stmt->fetchAll();
    
    if (empty($tables)) {
        echo "orders表不存在\n";
        exit;
    }
    
    // 获取表结构
    $stmt = $pdo->query('DESCRIBE orders');
    $columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo "orders表结构:\n";
    foreach ($columns as $column) {
        echo $column['Field'] . ' - ' . $column['Type'] . ' - ' . $column['Null'] . ' - ' . $column['Key'] . ' - ' . $column['Default'] . ' - ' . $column['Extra'] . "\n";
    }
    
    // 检查是否有sync_date字段
    $hasSyncDate = false;
    foreach ($columns as $column) {
        if ($column['Field'] === 'sync_date') {
            $hasSyncDate = true;
            break;
        }
    }
    
    if (!$hasSyncDate) {
        echo "\nsync_date字段不存在，正在添加...\n";
        $pdo->exec('ALTER TABLE orders ADD COLUMN sync_date DATETIME NULL COMMENT "同步日期"');
        echo "sync_date字段添加成功\n";
    } else {
        echo "\nsync_date字段已存在\n";
    }
    
} catch (Exception $e) {
    echo "错误: " . $e->getMessage() . "\n";
} 